var db = require('./utils/db');
var redis = require("./utils/redis")
var redisRpc = require("./utils/redisTaozi")
var mongoose = require("./model/db/mongoose");

const ClubUserModel =require("./model/ClubUserModel");
const PlatStatModel = require("./model/PlatStatModel");
const ClubModel = require("./model/ClubModel")
db.init({
    HOST:'39.105.101.213',
    USER:'dfnodeuser',
    PSWD:'LT7Ndm24tkkaGRk',
    DB:'dfnode',
    PORT:5626,
})

redis.init({
    host : "39.105.101.213",
    port : "6118",
    password : "1OHu%F$XY5%ecC!V",
    db:2
})

redisRpc.init({
    host : "39.105.101.213",
    port : "6118",
    password : "1OHu%F$XY5%ecC!V",
    db:1
})

mongoose.init({
    url : "mongodb://101.201.78.207:27717/dafu",
    auth : {
        user : "dafuuser",
        pass : "fbL0qffPmCAgQNZa",
    }
})
const fs = require("fs")
async function test(){
    let statInfo = {}
    PlatStatModel.find({dateType:1,type:1,createAt:{"$gte":1288540800}},{},{sort:{createAt:1}}, function(err, list){
        for(let i = 0; i< list.length; i++){
            let datestr = list[i].dateStr;
            statInfo[datestr] = statInfo[datestr] || {games:0,jushu:0};
            statInfo[datestr].games += list[i].gems;
            statInfo[datestr].jushu += list[i].jushu;
        }
        writeFile(statInfo)
    })
}

function writeFile(statInfo){
    fs.appendFileSync("大福耗钻.xls","日期\t耗钻数\t总局数\n")
    for(let datestr in statInfo){
        let info = statInfo[datestr]
        let str = datestr+"\t"+ info.games+"\t"+info.jushu+"\t\n";
        console.log(str)
        fs.appendFileSync("大福耗钻.xls",str)
    }
}

test();